import getApiData from '../../services/cpasRequest';

//获取树列表
export async function getTreeListApi(params: { dbname: string }) {
  if (!params.dbname) return [];
  const res = await getApiData('get.Supplier.type', params);
  if (res.ok) {
    return Promise.resolve({
      data: res.data,
      success: true,
    });
  }
  return Promise.resolve({
    data: [],
    success: false,
  });
}

//获取供应商月度table数据
export async function getTableListApi(params: {
  dbname: string;
  dataID: string | number | undefined;
  ranking: number | null; //排名，null是所有
  dates: any;
  dataField: any;
  typeName?: string | null;
}) {
  if (!params.dbname) return [];
  const res = await getApiData('Analysis.Inventory.GYSCGYD', params);
  if (res.ok) {
    return Promise.resolve({
      data: res.data,
      success: true,
    });
  }
  return Promise.resolve({
    data: [],
    success: false,
  });
}

//获取供应商年度table数据
export async function getYearTableListApi(params: {
  dbname: string;
  startYear: string;
  endYear: string;
  ranking: number | null; //排名，null是所有
  dates: any;
  typeName?: string | null;
}) {
  if (!params.dbname) return [];
  const res = await getApiData('Analysis.Inventory.GYSCGND', {
    ...params,
    dataFieldA: ['Qty', 'Money'],
    dataFieldB: ['Money'],
    dataFieldC: ['OrderIndex'],
  });
  if (res.ok) {
    return Promise.resolve({
      data: res.data,
      success: true,
    });
  }
  return Promise.resolve({
    data: [],
    success: false,
  });
}

//获取供应商商品年度table数据
export async function getGoodsYearTableListApi(params: {
  dbname: string;
  startYear: string;
  endYear: string;
  ranking?: number | null; //排名，null是所有
  dates: any;
  typeName?: string | null;
  supplierID?: string | number | null;
}) {
  if (!params.dbname) return [];
  const res = await getApiData('Analysis.Inventory.GYSCGSPND', {
    ...params,
    ranking: null,
    dataFieldA: ['Qty', 'Money'],
    dataFieldB: [
      {
        Qty: {
          field: 'Qty',
        },
        Money: {
          field: 'Money',
        },
      },
    ],
    dataFieldC: ['OrderIndex'],
  });
  if (res.ok) {
    return Promise.resolve({
      data: res.data,
      success: true,
    });
  }
  return Promise.resolve({
    data: [],
    success: false,
  });
}

//获取供应商商品月度table数据
export async function getGoodsMoonTableListApi(params: {
  dbname: string;
  dataID: string | number | undefined;
  typeName?: string | null;
  ranking?: null;
  dates?: any;
  dataField?: any;
  supplierID?: string | number | null;
}) {
  if (!params.dbname) return [];
  const res = await getApiData('Analysis.Inventory.GYSCGSPYD', {
    ...params,
    ranking: null,
    dates: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
    dataField: ['Qty', 'Money'],
    dataFieldB: [
      {
        Qty: {
          field: 'Qty',
        },
        Money: {
          field: 'Money',
        },
      },
    ],
  });
  if (res.ok) {
    return Promise.resolve({
      data: res.data,
      success: true,
    });
  }
  return Promise.resolve({
    data: [],
    success: false,
  });
}
